package com.xhwl.data.service.personal;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xhwl.common.dto.cent.sdata.OrganizationDTO;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.sdata.Account;
import com.xhwl.common.pojo.cent.sdata.Enterprise;
import com.xhwl.common.pojo.cent.sdata.Organization;
import com.xhwl.common.pojo.cent.sdata.PermissionGroup;
import com.xhwl.common.pojo.cent.sdata.personnel.Staff;
import com.xhwl.common.pojo.cent.sdata.personnel.StaffDTO;
import com.xhwl.common.query.cent.sdata.StaffAuditRecordQuery;
import com.xhwl.common.query.cent.sdata.StaffQuery;
import com.xhwl.data.pojo.personal.StaffFieldMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: luyi
 * @Description:
 * @Date: Create in 16:04 2022/2/8
 */
@RestController
public interface IStaffService extends IService<Staff> {

    /**
     * 新增员工信息
     * @param staffDTO 员工实体
     * @param operator 操作人
     * @return
     */
    @RequestMapping(value = "/staff-service/create", method = RequestMethod.POST)
    ResultJson create(@RequestPart StaffDTO staffDTO, @RequestPart Account operator);

    /**
     * 编辑
     * @param staffDTO
     * @param operator
     * @return
     */
    @RequestMapping(value = "/staff-service/edit", method = RequestMethod.POST)
    ResultJson edit(@RequestPart StaffDTO staffDTO,@RequestPart Account operator);

    /**
     * 分页查询
     * @param staffQuery
     * @param page
     * @return
     */
    @RequestMapping(value = "/staff-service/page", method = RequestMethod.POST)
    Page<StaffDTO> page(@RequestPart StaffQuery staffQuery, @RequestPart Page page);

    /**
     * 分页查询正常与离职员工
     * @param staffQuery
     * @param page
     * @return
     */
    @RequestMapping(value = "/staff-service/pageAll", method = RequestMethod.POST)
    Page<StaffDTO> pageAll(@RequestPart StaffQuery staffQuery, @RequestPart Page page);

    /**
     * 条件查询账号
     * @param staffQuery
     * @return
     */
    @RequestMapping(value = "/staff-service/pageAllAccount", method = RequestMethod.POST)
    List<Integer> pageAllAccountId(@RequestPart StaffQuery staffQuery);

    /**
     * 分页查询 给后端使用 返回的数据带上orgids 并且电话号码不脱敏，仅用于同步第三方
     * @param staffQuery
     * @param page
     * @return
     */
    @RequestMapping(value = "/staff-service/page/V2", method = RequestMethod.POST)
    Page<StaffDTO> pageWithOrgIds(@RequestPart StaffQuery staffQuery, @RequestPart Page page);

    StaffDTO deleteDetail(Integer id);

    /**
     * 详情
     * @param id
     * @return
     */
    @RequestMapping(value = "/staff-service/detail", method = RequestMethod.POST)
    StaffDTO detail(Integer id, Integer enterpriseId, Integer accountId, Integer industryId);

    /**
     * 员工绑定帐号
     * @param staffDTO
     * @param account
     * @return
     */
    @PostMapping(value = "/staff-service/bind")
    ResultJson bind(@RequestPart StaffDTO staffDTO, @RequestPart Account account);

    /**
     * 移除员工与该项目的的关联关系
     * @param staffId
     * @param projectId
     */
    void removeProject(Integer staffId, Integer projectId);

    /**
     * 根据员工查询项目
     * @param staffIds
     * @return key accountId, value 项目名称
     */
    Map<Integer, List<String>> findProjectMap(List<Integer> staffIds);

    /**
     * 根据员工查询项目
     * @param staffIds
     * @return
     */
    @RequestMapping(value = "/staff-service/find-project-map", method = RequestMethod.POST)
    ResultJson findProjectMap1(@RequestPart List<Integer> staffIds);
    /**
     * 根据帐号查询角色
     * @param accountIds
     * @return
     */
    Map<Integer, List<String>> findRoleMap(List<Integer> accountIds);

    /**
     * 根据员工查询部门
     * @param staffIds
     * @return
     */
    Map<Integer, List<String>> findDeptMap(List<Integer> staffIds);

    /**
     * 根据员工查询部门
     * @param staffIds
     * @return
     */
    Map<Integer, List<Organization>> findDeptAllEntityMap(List<Integer> staffIds);

    /**
     * 根据员工查询部门
     * @param staffIds
     * @return
     */
    @RequestMapping(value = "/staff-service/find-dept-map", method = RequestMethod.POST)
    ResultJson findDeptAllEntityMap1(@RequestPart List<Integer> staffIds);

    /**
     * 根据账号查询权限组
     * @param accountIds
     * @return
     */
    Map<Integer,List<PermissionGroup>> findPermissionMap(List<Integer> accountIds);

    /**
     * 根据企业id查询员工数量
     *
     * @param enterpriseIdList
     * @return
     */
    @RequestMapping(value = "/staff-service/find-byEnterpriseIdList", method = RequestMethod.POST)
    Map findByEnterpriseIdList(@RequestPart List<Integer> enterpriseIdList);

    /**
     * 查询企业下所有业务类型的员工
     *
     * @return
     */
    @RequestMapping(value = "/staff-service/find-all-businessIdStaff", method = RequestMethod.GET)
    Long findAllBusinessIdStaff();

    /**
     * 根据业务类型id查询员工数量
     *
     * @param businessIdList
     * @return
     */
    @RequestMapping(value = "/staff-service/find-byBusinessIdList", method = RequestMethod.POST)
    List findByBusinessIdList(@RequestPart List<Integer> businessIdList, @RequestPart Integer entId);


    /**
     * 查询园区下所有员工数量、公司员工数及排名
     *
     * @return
     */
    @RequestMapping(value = "/staff-service/find-all-staffs", method = RequestMethod.GET)
    Map findAllStaffs();

    /**
     * 删除员工
     * @param id
     * @return
     */
    @PostMapping("/staff-service/delete")
    ResultJson delete(@RequestPart(value = "industryId", required = false) Integer industryId, @RequestPart Integer id, @RequestPart Account operator);

    /**
     * 企业员工列表查询
     * @param staffQuery
     * @return
     */
    @RequestMapping(value = "/staff-service/list", method = RequestMethod.POST)
    List<StaffDTO> list(@RequestPart StaffQuery staffQuery);

    /**
     * 批量编辑员工的组织
     * @param staffIds
     * @param orgIds
     * @param enterpriseId
     * @return
     */
    ResultJson batchEditOrg(List<Integer> staffIds, List<Integer> orgIds, Integer enterpriseId);

    /**
     * 查询员工所在组织
     * @param staffQuery
     * @return
     */
    List<Integer> orgList(StaffQuery staffQuery);


    /**
     * 自动生成帐号的员工信息
     * @param enterpriseId
     * @return
     */
    ResultJson autoImport(Integer enterpriseId);

    @RequestMapping(value = "/staff-service/one", method = RequestMethod.POST)
    StaffDTO one(@RequestPart StaffQuery staffQuery);

    /**
     * 根据项目获取项目下的空间信息并标记关联
     * @param projectId
     * @return
     */
    List<OrganizationDTO> orgTree(Integer projectId, Integer accountId);

    /**
     * 审核
     *
     * @param recordId
     * @param pass
     * @param industryId
     * @return
     */
    ResultJson review(Integer recordId, Boolean pass, Integer industryId, Integer currentEnterpriseId);

    /**
     * 员工审核分页
     *
     * @param query
     * @param page
     * @param industryId
     * @return
     */
    Page pageReviewStaff(StaffAuditRecordQuery query, Page page, Integer industryId);

    /**
     * 员工审核企业列表
     *
     * @param currentEnterpriseId
     * @param likeEnterpriseName
     * @return
     */
    List<Enterprise> listReviewEnterprise(Integer currentEnterpriseId,String likeEnterpriseName);

    /**
     * 员工审核状态列表
     *
     * @param currentEnterpriseId
     * @param reviewEnterpriseId
     * @return
     */
    List<JSONObject> reviewStatus(Integer currentEnterpriseId, Integer reviewEnterpriseId);

    /**
     * 批量审核
     *
     * @param recordIds
     * @param pass
     * @param industryId
     * @return
     */
    ResultJson batchReview(List<Integer> recordIds, Boolean pass, Integer industryId, Integer currentEnterpriseId);

    /**
     * 员工审核详情
     *
     * @param recordId
     * @param industryId
     * @return
     */
    JSONObject reviewDetail(Integer recordId, Integer industryId, Integer currentEnterpriseId);


    StaffFieldMap staffFieldViewHandler(List<StaffDTO> records);

    @RequestMapping(value = "/staff-service/findByWorkCode", method = RequestMethod.POST)
    Staff findByWorkCode(String workCode);
    /**
     * 查企业下的人员
     */
    @RequestMapping(value = "/staff-service/findByEntIds", method = RequestMethod.POST)
    List<StaffDTO> findByEntIds(@RequestPart List<Integer> entIds);

    /**
     * 查组织下的人员
     */
    @RequestMapping(value = "/staff-service/findByOrgIds", method = RequestMethod.POST)
    List<StaffDTO> findByOrgIds(@RequestPart List<Integer> orgIds);

    /**
     * 查组织或企业下的人员
     * type : 1组织，2企业
     */
    @RequestMapping(value = "/staff-service/findAccountId", method = RequestMethod.POST)
    List<Integer> findAccountId(@RequestPart List<Integer> ids,@RequestPart Integer type);
}
